<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <script>
        function fibonacciIterative(n) {
            if(n < 1) return 0;
            if(n <= 2) return 1;
            
            let fibNum2 = 0;
            let fibNum1 = 1;
            let fib = n;
            for (let i = 2; i <= n; i++) {
                fib = fibNum1 + fibNum2; // f(n-1) + f(n-2)
                fibNum2 = fibNum1;
                fibNum1 = fib;
            }
            return fib;
        }
        console.log(fibonacciIterative(10));
    </script>
</body>
</html>